package main

import (
	"fmt"
	"time"
)

func count(c chan<- int) {
	for i := 0; i < 10; i++ {
		time.Sleep(2 * time.Second)
		c <- i
	}
	close(c)
}

/*
调试：
go build -gcflags "-N -l" main.go   # -N -l忽略Go内部做的一些优化，聚合变量和函数等优化
gdb main
*/

func main() {
	msg := "Starting main"
	fmt.Println(msg)
	bus := make(chan int)
	go count(bus)
	for count := range bus {
		fmt.Println("count:", count)
	}
}
